package com.dzk.cp.c11x5.index.rx.cs;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.dzk.cp.c11x5.constant.C11x5Attrs;
import com.dzk.cp.c11x5.index.BaseC11x5Index;
import com.dzk.cp.c11x5.pojo.R5;
import com.dzk.cp.c11x5.util.C11x5Utils;
import com.dzk.cp.c11x5.util.SpringBeanUtils;

public abstract class RXnCSIndex extends BaseC11x5Index {
	
	public RXnCSIndex setParams(int code, int num, int unit) {
		super.setParams(code, num, unit);
		return this;
	}
	
	@Override
	public Map<String, Integer> index() {
		Map<String, Integer> resultMap = new LinkedHashMap<String, Integer>();
		List<String> rxcs = getAllRXn();
		List<? extends R5> r5s = SpringBeanUtils.getR5Service(code).queryLatest(getLastestNum());
		for (String rxc : rxcs) {
			resultMap.put(rxc, getCS(r5s, rxc));
		}
		return resultMap;
	}

	public static Integer getCS(List<? extends R5> r5s, String rxc) {
		int sx = 0;
		String[] rxArr = rxc.split(" ");
		for (R5 r5 : r5s) {
			if (C11x5Utils.contain(r5.getNs().split(" "), rxArr)) {
				sx++;
			}
		}
		return sx;
	}
	
	protected abstract List<String> getAllRXn();
	
	public static RXnCSIndex getInstance(int code, int num, int unit, int n) {
		switch (n) {
		case 1:
			return new RX1CSIndex().setParams(code, num, unit);
		case 2:
			return new RX2CSIndex().setParams(code, num, unit);
		case 3:
			return new RX3CSIndex().setParams(code, num, unit);
		case 4:
			return new RX4CSIndex().setParams(code, num, unit);
		case 5:
			return new RX5CSIndex().setParams(code, num, unit);
		case 6:
			return new RX6CSIndex().setParams(code, num, unit);
		case 7:
			return new RX7CSIndex().setParams(code, num, unit);
		case 8:
			return new RX8CSIndex().setParams(code, num, unit);
		case 9:
			return new RX9CSIndex().setParams(code, num, unit);
		default:
			return null;
		}
	}

}

class RX1CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return Arrays.asList(new String[] {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11"});
	}

	@Override
	protected int getZQ() {
		return 11 / 5;
	}

}

class RX2CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX2();
	}

	@Override
	protected int getZQ() {
		return 55 / 10;
	}

}

class RX3CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX3();
	}

	@Override
	protected int getZQ() {
		return 165 / 10;
	}

}

class RX4CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX4();
	}

	@Override
	protected int getZQ() {
		return 66;
	}

}

class RX5CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX5();
	}

	@Override
	protected int getZQ() {
		return 462;
	}

}

class RX6CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX6();
	}

	@Override
	protected int getZQ() {
		return 78;
	}

}

class RX7CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX7();
	}

	@Override
	protected int getZQ() {
		return 22;
	}

}

class RX8CSIndex extends RXnCSIndex {

	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX8();
	}

	@Override
	protected int getZQ() {
		return 33 / 4;
	}

}

class RX9CSIndex extends RXnCSIndex {
	
	@Override
	protected List<String> getAllRXn() {
		return C11x5Attrs.getAllRX9();
	}

	@Override
	protected int getZQ() {
		return 11 / 3;
	}

}
